import asyncio

from api_utils.base_data_api import BaseDate, get_user_info, get_store_list
from database.models.store_model import StoreData


class StoreOperation:

    def __init__(self):
        pass

    @staticmethod
    def handle_store_info():
        base_data = BaseDate()
        response = asyncio.run(get_store_list(base_data))
        if response.message != "success":
            return False
        all_store_data = response.data
        StoreData.insert_store_info(all_store_data)

    @staticmethod
    def get_sid_list():
        base_data = BaseDate()
        response = asyncio.run(get_store_list(base_data))
        new_sid_list = []
        if response.message != "success":
            print("店铺信息获取失败")
        all_user_data = response.data
        for store in all_user_data:
            sid = store.get("sid")
            new_sid_list.append(sid)
        return new_sid_list

    @staticmethod
    def get_store_id_list():
        old_sid_list = StoreData.get_sid_list()
        return old_sid_list

if __name__ == '__main__':
    StoreOperation.handle_store_info()